<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('城市新增')"/>
</head>
<body>
<form class="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">市代码</label>
                    <div class="layui-input-block">
                        <input type="text" name="cityCode" lay-verify="cityCode" autocomplete="off" placeholder="市代码" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">市名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="cityName" autocomplete="off"  class="layui-input" placeholder="市名称">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">简称</label>
                    <div class="layui-input-block">
                        <input type="text" name="shortName" autocomplete="off"  class="layui-input" placeholder="简称">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">省代码</label>
                    <div class="layui-input-block">
                        <select name="provinceCode">
							<option th:each="list : ${sysProvinces}" th:text="${list.provinceName}" th:value="${list.provinceCode}"></option>
						</select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">经度</label>
                    <div class="layui-input-block">
                        <input type="text" name="lng" autocomplete="off"  class="layui-input" placeholder="经度">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">纬度</label>
                    <div class="layui-input-block">
                        <input type="text" name="lat" autocomplete="off"  class="layui-input" placeholder="纬度">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="number" name="sort" autocomplete="off"  class="layui-input" placeholder="排序">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <select name="dataState" id="dataState" th:with="type=${@dict.getType('sys_province_state')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="sysCity-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'jquery'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let MODULE_PATH = rootPath+"/SysCityController";
        //名称验证
        form.verify({
            interName: function(value){
                if(value.length < 2){
                    return '至少得2个字符';
                }
                var msg = "";
                $.ajax({
                    url: MODULE_PATH+'/checkNameUnique',
                    data: "interName="+value,
                    dataType: 'json',
                    type: 'post',
                    async:false,
                    success: function (result) {
                            msg=result;
                    }
                });
                if (msg == 1) {
                   return "已有相同数据";
                }

            }
        });



        //保存
        form.on('submit(sysCity-save)', function (data) {
            $.ajax({
                url: MODULE_PATH+'/add',
                data: data.field,
                dataType: 'json',
                contentType: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code==200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.layui.table.reload("sysCity-table");
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
</body>
</html>